<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<style>

    body .demo-class .layui-layer-btn0 {
        border-color: #e2e2e2;
        background-color: #fff;
        color: #333;
    }
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" id="formInfo">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">供应商</label>
                        <div class="layui-input-inline" >
                            <select name="supplier" lay-filter="selectInfo">
                                <option value=""></option>
                                {volist name="supplier" id="v"}
                                <option value="{$v.id}">{$v.supplier_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                </div>

        </form>

     <!--   <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>-->

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">结款记录</a>
        </script>
    </div>
</div>
{include file="public/footer" /}
<script type="text/html" id="look">
    <button data-method="offset" data-type="auto" class="layui-btn lookstyle" lay-event="look">查看</button>
</script>


<script type="text/html" id="matchingType">

    {{#  if(d.status === 1){ }}
    <span style="color: #28f51d;">展示中</span>
    {{# }else if(d.status === 2){ }}
    <span style="color: #f59b28;">待展示</span>
    {{# }else if(d.status === 3){ }}
    <span style="color: #f42540;">已结束</span>
    {{#  } }}



</script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        var type = $("input[name='type']").val();


        let arr_data={
            elem: '#currentTableId',
            url: '/admin/supplierpayment/fee_index?active=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter'],

            cols: [[
                // {type: "checkbox",},
                {field: 'supplier_name', title: '供应商名称'},
                // {field: 'bizpro_class', title: '供应商分类',toolbar: '#look'},
                {field: 'bizpro_class', title: '供应商分类'},
                {field: 'relation_phone', title: '联系方式'},
                {field: 'total_price', title: '累计销售额',sort:true},
                {field: 'total_pay', title: '累计结款额',sort:true},
                {field: 'pay_price', title: '剩余应结额',sort:true},
                {field: 'pay_number', title: '结款次数',sort:true},
                {title: '操作', toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        }
        table.render(
            arr_data
        );

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });
        form.on('select(selectInfo)', function (data) {
            submitInfo();
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '创建消息',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/cost/saveinfo',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var id = obj.data.id;
            var explain = obj.data.explain;
            var account_name = obj.data.account_name;
            var bank_account = obj.data.bank_account;
            var open_bank = obj.data.open_bank;
            var bank_address = obj.data.bank_address;
            var rendor = form.render();

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/supplierpayment/log_fee?id="+id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else  if (obj.event === 'look') {
                $("#account_name").val(account_name);
                //触发事件  查看内容
                var index = layer.open({
                    title:'收款信息',
                    type: 1,
                    area: ['50%','50%' ],
                    fixed: false, //不固定
                    shade:0.5,
                    shadeClose:true,
                    content:"<div class=\"layui-row\">\n" +
                        "        <form class=\"layui-form\">\n" +
                        "            <div class=\"layui-form-item \">\n" +
                        "                <div class=\"layui-form-item flex-box flex-box-justify\" style='margin-top: 25px;'>\n" +
                        "                    <label for=\"account_name\" class=\"layui-form-label\">\n" +
                        "                        户名\n" +
                        "                    </label>\n" +
                        "                    <div class=\"layui-input-inline\" style=\"width:20%;height:50px;\">\n" +
                        "                        <input type=\"text\" id=\"account_name\" name=\"account_name\" value='"+account_name+"'\n" +
                        "                               required=\"\" autocomplete=\"off\" class=\"layui-input\" lay-verify=\"account_name\" style=\"height:100%;width: 350%;\">\n" +
                        "                    </div>\n" +
                        "                </div>\n" +
                        "                <div class=\"layui-form-item flex-box flex-box-justify\">\n" +
                        "                    <label for=\"bank_account\" class=\"layui-form-label\">\n" +
                        "                        账号\n" +
                        "                    </label>\n" +
                        "                    <div class=\"layui-input-inline \" style=\"width:20%;height:50px;\">\n" +
                        "                        <input type=\"text\" id=\"bank_account\" name=\"bank_account\" value='"+bank_account+"'\n" +
                        "                               required=\"\" autocomplete=\"off\" class=\"layui-input \" lay-verify=\"bank_account\" style=\"height:100%;width: 350%;\" >\n" +
                        "                    </div>\n" +
                        "                </div>\n" +
                        "\n" +
                        "\n" +
                        "                <div class=\"layui-form-item flex-box flex-box-justify\">\n" +
                        "                    <label for=\"bank_name\" class=\"layui-form-label\">\n" +
                        "                        银行名称\n" +
                        "                    </label>\n" +
                        "                    <div class=\"layui-input-inline \" style=\"width:20%;height:50px;\">\n" +
                        "                        <input type=\"text\" id=\"bank_name\" name=\"bank_name\" value='"+open_bank+"'\n" +
                        "                               required=\"\" autocomplete=\"off\" class=\"layui-input \" lay-verify=\"bank_name\" style=\"height:100%;width: 350%;\" >\n" +
                        "                    </div>\n" +
                        "                </div>\n" +
                        "                <div class=\"layui-form-item flex-box flex-box-justify\">\n" +
                        "                    <label for=\"open_bank\" class=\"layui-form-label\">\n" +
                        "                       开户行\n" +
                        "                    </label>\n" +
                        "                    <div class=\"layui-input-inline hight-div\" style=\"width:20%;height:50px;\">\n" +
                        "                        <input type=\"text\" id=\"open_bank\" name=\"open_bank\" value='"+bank_address+"'\n" +
                        "                               required=\"\" autocomplete=\"off\" class=\"layui-input \" lay-verify=\"open_bank\" style=\"height:100%;width: 350%;\">\n" +
                        "                    </div>\n" +
                        "                </div>\n" +
                        "            </div>\n" +

                        "        </form>\n" +
                        "    </div>" ,
                });
            } else  if (obj.event === 'lookMember') {
                getMemberAjax('',id,'');
            } else  if (obj.event === 'delete') {
                layer.confirm('确定要删除么?', function (index) {
                    //发异步删除数据
                    $.ajax({
                        url: '/admin/supplierpayment/del',
                        type: 'post',
                        dataType: 'json',
                        data: {id: id},
                        success: function (data) {
                            if (data.status) {
                                layer.msg('删除成功!', {
                                    icon: 1,
                                    time: 1000
                                });
                                obj.del();

                            }
                        },
                        error: function () {
                            layer.msg("删除失败");
                        }
                    });
                    layer.close(index);
                });

            }
        });
        function submitInfo() {
            var d = {};
            var t = $('#formInfo [name]').serializeArray();
            $.each(t, function () {
                d[this.name] = this.value;
            });
            var result = JSON.stringify(d);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        };

    });
    //用户类型  显示用户名称
    function selectMemberType(name){
        // 选择合伙人
        layer.open({
            type: 1,
            title: "用户名称",
            area: ['1000px', '630px'],
            shade: 0.5,
            maxmin: true,
            content: "     <div class=\"layui-form-item\">\n" +
                "                <label class=\"layui-form-label\" style=\"margin-left:-1px;\">用户名称</label>\n" +
                "                <div class=\"layui-input-block showuser\"  style='padding:0px 0px 10px;box-sizing:border-box;width:1200px;overflow: auto;display: flex;flex-wrap: wrap;justify-content: flex-start'>\n" +
                "\n" +
                "\n" +           name +
                "                </div>\n" +
                "            </div>",
        })
        layer.close(index);
    }
    //选择等级时 ajax
    function getMemberAjax(memberLevel,id,peopleType){
        $.ajax({
            url: '/admin/notice/look_member?people_type='+peopleType+'&member_level='+memberLevel+'&notice_id='+id,
            type: 'post',
            dataType: 'json',
            data: '',
            success: function (data) {
                var str = data.str;
                if (data.status == true) {
                    selectMemberType(str);

                }else{
                    layer.msg(data.msg,{icon:5,time:1000})
                }
            },
            error: function () {
                layer.msg("失败");
            }
        });
        return false
    }
</script>

</body>
</html>